package com.dgd.test.demo.service.impl;

import com.dgd.test.demo.bean.TeacheBean;
import com.dgd.test.demo.globalecxeption.EduException;
import com.dgd.test.demo.mapper.EduTeacherMapper;
import com.dgd.test.demo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @program: 726
 * @description:
 * @author: Jaime
 * @create: 2021-07-28 13:58
 **/
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private EduTeacherMapper eduTeacherMapper;

    /**
     * mybatis 数据库查询
     * @param teacherId
     * @return
     */
    @Override
    public TeacheBean findTeacher(Integer teacherId) {
        TeacheBean teacher = eduTeacherMapper.findTeacherById(teacherId);
        return teacher;
    }

    @Override
    public int addTeacher(TeacheBean teacher) {
        Date date = new Date();
        teacher.setIsDeleted(false);
        teacher.setGmtModified(date);
        teacher.setGmtCreate(date);
        int i = eduTeacherMapper.addTeacher(teacher);

        if (i==0){
            throw new EduException("添加讲师到数据库失败");
        }
        return i;
    }

    @Override
    public int deleteTeacher(List<Integer> ids) {
        System.out.println(ids);
        int i = eduTeacherMapper.deleteTeacher(ids);
        if (i==0){
            throw new EduException("删除讲师到数据库失败");
        }
        return i;
    }

/*    @Override
    public int deleteTeacher(List<Integer> ids) {
        int i = teacherMapper.delteTeacher(ids);
        if(i==0){
            throw new EduExcetion("删除讲师失败");
        }
        return i;
    }*/

    @Override
    public int updateTeacher(TeacheBean teacher) {
        teacher.setGmtModified(new Date());
        int i = eduTeacherMapper.updateTeacher(teacher);
        if(i==0){
            throw new EduException("修改讲师失败");
        }
        return i;
    }

    /*    *//**
     * 测试异常的代码
     * @param teacherId
     * @return
     *//*
    @Override
    public TeacheBean findTeacher(Integer teacherId) {
        TeacheBean teacher = new TeacheBean();
        teacher.setId(teacherId);
        teacher.setName("迪丽热巴");
        teacher.setIntro("新疆");
        teacher.setLevel(1);
        teacher.setCareer("搞不搞");
        teacher.setAvatar("2154548478");
        teacher.setDeleted(false);
        teacher.setSort(1);
        int a = 1/0;
        Date date = new Date();
        teacher.setGmtModified(date);
        teacher.setGmtModified(date);
        return teacher;
    }*/


}
